import {request, handleFetchResultNotification, REQUEST_TYPE} from '../../utils';
import {formatMessage} from '../localize';
import stringify from 'Shared/utils/stringify';
const baseUrl = '/afterSales/api/v1';

const categoryDesc = formatMessage({
    id: 'api.categoryDesc',
    defaultMessage: '查询故障代码'
});
const faultItemCategoriesDesc = formatMessage({
    id: 'api.faultItemCategoriesDesc',
    defaultMessage: '查询故障代码分类'
});

//查询故障代码
export const getFaultItem = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/faultItems?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, categoryDesc));
};
//故障代码快捷查询
export const getFaultItemQuickly = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/faultItems/simple?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, categoryDesc));
};
// 查询顶层分类
export const getCategoriesTop = () => request(`${baseUrl}/faultItemCategories/topLevel`, null, null)
    .then(handleFetchResultNotification(REQUEST_TYPE.query, faultItemCategoriesDesc));

// 查询分类
export const getCategories = id => request(`${baseUrl}/faultItemCategories/${id}/children`, null, null)
    .then(handleFetchResultNotification(REQUEST_TYPE.query, faultItemCategoriesDesc));
